#include <windows.h>											// Header File For Windows
#include "InputManager.h"

#define W_KEY 0x57
#define A_KEY 0x41
#define D_KEY 0x44
#define E_KEY 0x45
#define F_KEY 0x46
#define Q_KEY 0x51
#define S_KEY 0x53
#define T_KEY 0x54
#define X_KEY 0x58
#define Z_KEY 0x5A

// Static members...
InputManagerC* InputManagerC::sInstance			= NULL;
bool8_t InputManagerC::s_bJumpValid				= false;
bool8_t InputManagerC::s_bLookForJumpRelease    = false;
bool8_t InputManagerC::s_bDashValid             = false;
bool8_t InputManagerC::s_bLookForDashRelease    = false;
bool8_t InputManagerC::s_bToggleValid           = false;
bool8_t InputManagerC::s_bLookForToggleRelease  = false;

InputManagerC *InputManagerC::CreateInstance()
{
	if(sInstance!=NULL)return sInstance;
	else

	sInstance = new InputManagerC();
	return sInstance;
}

void InputManagerC::update(float_t argDelta)
{
	if (g_keys->keyDown[VK_ESCAPE])								// Is ESC Being Pressed?
	{
		TerminateApplication (g_window);						// Terminate The Program
	}

	if (g_keys->keyDown[VK_F1])									// Is F1 Being Pressed?
	{
		ToggleFullscreen (g_window);							// Toggle Fullscreen Mode
	}

	// Process jump requests
	JumpPressed();
	// Process dash requests
	DashPressed();
	// Process view toggle
	ViewToggle();
}

bool8_t InputManagerC::IsMovingForward()
{
	return g_keys->keyDown[W_KEY];
}

bool8_t InputManagerC::IsMovingBackward()
{
	return g_keys->keyDown[S_KEY];
}

bool8_t InputManagerC::IsMovingRight()
{
	return g_keys->keyDown[D_KEY];
}

bool8_t InputManagerC::IsMovingLeft()
{
	return g_keys->keyDown[A_KEY];
}

bool8_t InputManagerC::IsMovingUp()
{
	return g_keys->keyDown[E_KEY];
}

bool8_t InputManagerC::IsMovingDown()
{
	return g_keys->keyDown[Q_KEY];
}

bool8_t InputManagerC::IsRotatingYawCC()
{
	return g_keys->keyDown[Z_KEY];
}

bool8_t InputManagerC::IsRotatingYawCW()
{
	return g_keys->keyDown[X_KEY];
}


bool8_t InputManagerC::IsRotatingPitch()
{
	return false;
}

void InputManagerC::JumpPressed()
{
	s_bJumpValid = false;

	if(s_bLookForJumpRelease)
	{
		if(!g_keys->keyDown[VK_SPACE])
		{
			s_bLookForJumpRelease = false;
		}
	}
	if(g_keys->keyDown[VK_SPACE] && !s_bLookForJumpRelease)
	{
		s_bJumpValid = true;
		s_bLookForJumpRelease = true;
	}
}

void InputManagerC::DashPressed()
{
	s_bDashValid = false;

	if(s_bLookForDashRelease)
	{
		if(!g_keys->keyDown[F_KEY])
		{
			s_bLookForDashRelease = false;
		}
	}
	if(g_keys->keyDown[F_KEY] && !s_bLookForDashRelease)
	{
		s_bDashValid = true;
		s_bLookForDashRelease = true;
	}
}

void InputManagerC::ViewToggle()
{
	s_bToggleValid = false;

	if(s_bLookForToggleRelease)
	{
		if(!g_keys->keyDown[T_KEY])
		{
			s_bLookForToggleRelease = false;
		}
	}
	if(g_keys->keyDown[T_KEY] && !s_bLookForToggleRelease)
	{
		s_bToggleValid = true;
		s_bLookForToggleRelease = true;
	}
}

bool8_t InputManagerC::IsJumping()
{
	return s_bJumpValid;
}

bool8_t InputManagerC::IsDashing()
{
	return s_bDashValid;
}

bool8_t InputManagerC::IsToggle()
{
	return s_bToggleValid;
}
